<?php

if(isset($_POST['dirIdEdit']) && isset($_POST['dirNameEdit']) && isset($UID)){
#if it is a dirAdd request

  $dirIdEdit   = $_POST['dirIdEdit'];
  $dirNameEdit = $_POST['dirNameEdit'];

  require_once $BASE_PATH . 'm/dir.php';

  $dircn = new DIR(DBHOST, DBUSER, DBPASS, DBNAME);

  $dirEdit = $dircn->getById($dirIdEdit);

  if($dirEdit !== false){

    if($dircn->alt($dirEdit['id'], $dirEdit['parent'], $dirNameEdit, $dirEdit['subdir'] + 1, $dirEdit['file'], $dirEdit['uid'])){

      require_once $BASE_PATH . 'm/bookmark.php';
      $bmcn = new Bookmark(DBHOST, DBUSER, DBPASS, DBNAME);
      $bookmark = $bmcn->get($UID);

      echo '{"code": 0, "data":' . json_encode($bookmark) . '}';

    }else{
      echo '{"code": 1, "message": "fail to change name"}';
    }

  }else{
    echo '{"code": 2, "message": "fail to get dir"}';
  }

}
